package com.secxiot.consumer.system.service;

import com.secxiot.consumer.user.feign.UserClient;
import com.secxiot.provider.system.vo.DataDictVo;
import com.secxiot.provider.system.vo.UserTypeVo;
import com.secxiot.provider.user.entity.UserDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SystemConsumerService {


    @Autowired
    private UserClient userClient;

    public List<UserTypeVo> getUserTypeList(Long userId, String taskType){
        UserDo user = userClient.getUser(userId);
        String userType = user.getType();
        List<UserTypeVo> typeVos = new ArrayList<>(2);
        UserTypeVo docs = new UserTypeVo();
        docs.setDisplayName("医护");
        UserTypeVo patients = new UserTypeVo();
        patients.setDisplayName("患者");
        patients.getUserTypes().add("0000100001");

        if ("0000200003".equals(taskType)) {
            //交接类型，限定为医护且类型保持一致
            docs.getUserTypes().add(userType);
            typeVos.add(docs);
            return typeVos;
        }

        List<DataDictVo> dicts = userClient.listDataDict("00001");
        dicts.stream()
                .filter(dataDictVo -> !dataDictVo.getCode().equals("0000100001"))
                .forEach(d -> docs.getUserTypes().add(d.getCode()));
        if ("0000200005".equals(taskType)){
            //SOS出诊，限定为医护
            typeVos.add(docs);
            return typeVos;
        }

        //SOS出诊，限定为医护
        typeVos.add(docs);
        typeVos.add(patients);
        return typeVos;
    }
}
